from aiogram import types
from aiogram.filters.callback_data import CallbackData
from aiogram_dialog import DialogManager
from fluentogram import TranslatorRunner

from src.database.services import CalendarService


async def accept_calendar_task_answer(
    call: types.CallbackQuery,
    callback_data: CallbackData,
    dialog_manager: DialogManager,
):
    """Зассчитываем ответ по заданию календаря"""

    locale: TranslatorRunner = dialog_manager.middleware_data.get("locale")
    calendar_service: CalendarService = dialog_manager.middleware_data.get(
        "calendar_service"
    )

    await calendar_service.update_calendar_successful_tasks(
        callback_data.user_calendar_id
    )
    await call.answer(locale.get("task-reply-accepted"))
    await call.message.delete()
